var app, ns;
app = new Vue({
    el: '#app',
    data: {
    },
    methods: {
        get_data: function () {
            var that = this;
            // api.removePrefs({
            //     key: 'agreementDone'
            // });
            var agreementDone = api.getPrefs({
                sync: true,
                key: 'agreementDone'
            });
            if (!agreementDone) {
                that.open_agreenment();
                return;
            }
            that.open_home_index();
            setTimeout(function () {
                that.open_intro_index();
            }, 2000);
        },
        open_agreenment(){
            var delay = 0;
            if (api.systemType != 'ios') {
                delay = 100;
            }
            api.openFrame({
                name: 'agreement_index',
                url: 'agreement.html',
                delay: delay,
                slidBackEnabled: false,
                vScrollBarEnabled: false,
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: 'auto'
                }
            });
        },
        open_home_index: function () {
            var delay = 0;
            if (api.systemType != 'ios') {
                delay = 100;
            }
            api.openFrame({
                name: 'main_home_index',
                url: 'home_index.html',
                delay: delay,
                slidBackEnabled: false,
                vScrollBarEnabled: false,
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: 'auto'
                }
            });
        },
        open_intro_index: function () {
            var delay = 0;
            if (api.systemType != 'ios') {
                delay = 100;
            }
            api.openTabLayout({
                hideNavigationBar: true,
                hideTabBar: true,
                useWKWebView: true,
                name: 'intro_index',
                url: 'intro_index.html',
                delay: delay,
                slidBackEnabled: false,
                vScrollBarEnabled: false,
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: 'auto'
                }
            });
        },
        set_status_bar: function () {
            api.setStatusBarStyle({
                style: 'dark',
                color: 'transparent'
            });
        },
        
        // open_xieyi_index: function(type) {
        //     api.openFrame({
        //         name: 'dl_register_agree_frm',
        //         url: 'html/dl_register_agree_frm.html',
        //         slidBackEnabled: false,
        //         vScrollBarEnabled: false,
        //         bgColor: 'rgba(0,0,0,0.6)',
        //         rect: {
        //             x: 0,
        //             y: 0,
        //             w: 'auto',
        //             h: 'auto'
        //         },
        //         pageParam: {
        //             Type: type,
        //             answer:1
        //         }
        //     });
        // },

    }
});
apiready = function () {
    app.set_status_bar();
    api.parseTapmode();
    ns = window.Foresight.Util;
    var last_out_time;
    app.get_data();
    api.addEventListener({
        name: 'keyback'
    }, function (ret, err) {
        if (last_out_time && last_out_time.valueOf() >= (new Date().valueOf() - 1000)) {
            api.closeWidget({
                silent: true
            });
            return;
        }
        last_out_time = new Date();
        api.toast({
            msg: '再按一次退出程序',
            duration: 1000
        });
    });
};
